<?php
/**
 * @var $model Video
 */
?>
    <h1 class="title"><?php echo $model->title; ?></h1>
    <abbr class="date">Đăng bởi <span style="color: red;font-weight: bold;"><?php echo $model->user->username ?></span>
        vào lúc: <?php echo date('H:i', $model->create_time); ?> ngày  <?php echo date('d/m/Y', $model->create_time); ?>
    </abbr>

    <div style="margin-top: 20px;" id="video">
        <div class=""></div>
        <?php if ($model->youtube) { ?>
        <iframe width="520" height="300" src="<?php echo str_replace("watch?v=", 'embed/', $model->youtube); ?>"
                frameborder="0" allowfullscreen></iframe>
        <?php } else { ?>
        <?php
        $this->widget('ext.jwplayer.JwPlayer', array(
            'rtmpPath' => '',
            'width' => 520,
            'height' => 300,
            'flvName' => Yii::app()->homeUrl . $model->file->path,
            'autoStart' => false
        ));
        ?>
        <?php } ?>
    </div>
    <div id="rate" style="margin-top: 20px;">
        <span id="star">
        <?php for ($i = 1; $i <= $model->star; $i++): ?>
            <img src="<?php echo Yii::app()->baseUrl; ?>/images/star.png">
            <?php endfor; ?>
            </span>
       <span id="av">
        <?php
           if ($model->rateCount > 0) {
               echo '<b>(' . $model->averrate . ', ' . $model->rateCount . ' votes)</b>';
           }
           ?>
           </span>
        <?php echo CHtml::beginForm(); ?>
        <?php echo CHtml::listBox('marks', 0, array(0 => 'vote', 1 => '1 - Tồi', 2, 3, 4, 5 => '5 - TB', 6, 7, 8, 9, 10 => '10 - Tốt'), array('size' => 1)); ?>
        <?php echo CHtml::ajaxSubmitButton('Rate', $this->createUrl('rate', array('id' => $model->id)), array('success' => 'js: function(data) {
                        if(data){
                            //var obj = JSON.parse(data);
                            if(data.login == 1){
                                alert("Bạn cần phải đăng nhập.");
                            }
                            if(data.success == 1){
                                window.location.reload();
                            }
                        }

                    }')); ?>
        <?php echo CHtml::endForm();?>
    </div>
    <div style="margin: 20px 0px;"><?php echo $model->body ?></div>
<div style="margin: 10px 0px;">
    <!-- AddThis Button BEGIN -->
    <div class="addthis_toolbox addthis_default_style ">
        <a class="addthis_button_facebook_like" fb:like:layout="button_count"></a>
        <a class="addthis_button_tweet"></a>
        <a class="addthis_button_google_plusone" g:plusone:size="medium"></a>
        <a class="addthis_counter addthis_pill_style"></a>
    </div>
    <script type="text/javascript">//var addthis_config = {"data_track_addressbar":true};</script>
    <script type="text/javascript"
            src="http://s7.addthis.com/js/250/addthis_widget.js#pubid=ra-4f88f64654f5680c"></script>
    <!-- AddThis Button END -->
</div>
<div id="comments">
    <?php if ($model->commentCount >= 1): ?>
    <h2>
        <?php echo $model->commentCount . ' Comments'; ?>
    </h2>

    <?php $this->renderPartial('_comments', array(
        'training' => $model,
        'comments' => $model->comments,
    )); ?>
    <?php endif; ?>

    <?php if (!Yii::app()->user->isGuest): ?>
    <h3 style="margin-top: 1em;">Gửi bình luận</h3>

    <?php if (Yii::app()->user->hasFlash('commentSubmitted')): ?>
        <div class="flash-success">
            <?php echo Yii::app()->user->getFlash('commentSubmitted'); ?>
        </div>
        <?php else: ?>
        <?php $this->renderPartial('/comment/_form', array(
            'model' => $comment,
        )); ?>
        <?php endif; ?>
    <?php else: ?>
    <div> <?php echo CHtml::link('Đăng nhập', $this->createUrl('/site/login')); ?> để đăng bình luận.</div>
    <?php endif; ?>
    <div style="border-top: 1px solid #ccc">
        <h2 style="padding: 5px">Bình luận từ Facebook</h2>
        <div class="fb-comments" data-href="http://hocgioi.com.vn/lnt" data-num-posts="2" data-width="470"></div>
    </div>
</div>
<!-- comments -->